const http = require('http');
const server = http.createServer();
server.listen(3000,()=>{
  console.log('服务器已启动');
});
const path = require('path');
const fs = require('fs');
server.on('request',(req,res)=>{
  const url = req.url;
  res.sendfile = function(fpath){
    fs.readFile(path.join(__dirname,fpath),(err,data)=>{
      if(err){
        console.log(err);
        return res.end('404 not found');
      }
      res.end(data)
    })
  }
  if(url === '/addcate'){
    res.sendfile('/view/addcate.html')
  }else if(url === '/cate'){
    res.sendfile('/view/cate.html')
  }else if(url.startsWith('/assets')){
    console.log(url)
    res.sendfile('/view'+url);
  }
  else{
    res.end('404 not found');
  }
})